﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Frame.Lib.Common
{
    public class EnumInfo
    {
        public EnumInfo() { }
        public EnumInfo(int id, string name)
        {
            this.ID = id;
            this.Name = name;
        }
        public string Name
        {
            get;
            set;
        }
        public int ID
        {
            get;
            set;
        }

        public object Tag
        {
            get;
            set;
        }

        public static List<EnumInfo> Convert(Type enumType)
        {
            List<EnumInfo> lstInfos = new List<EnumInfo>();

            int[] values = (int[])Enum.GetValues(enumType);
            foreach (int i in values)
            {
                EnumInfo info = new EnumInfo();
                info.ID = i;
                info.Name = Enum.GetName(enumType, i);
                lstInfos.Add(info);
            }
            return lstInfos;
        }

        public static void BindList(System.Web.UI.WebControls.ListControl ctl, Type enumType)
        {
            List<EnumInfo> lstInfos = Convert(enumType);
            
            ctl.DataSource = lstInfos;
            ctl.DataTextField = "Name";
            ctl.DataValueField = "ID";
            ctl.DataBind();
        }
    }
}
